#include "mainwindow.h"
#include <QDebug>
#include <QFileDialog>

MainWindow::MainWindow()
{
	form.setupUi(this);
	mainWidget = new MainWidget();
	this->setCentralWidget(mainWidget);
	this->setWindowTitle("Loadtester");

	QObject::connect(form.actionSave, SIGNAL(triggered()), this, SLOT(SaveScenarioHandle()));
	QObject::connect(form.actionLoad, SIGNAL(triggered()), this, SLOT(LoadScenarioHandle()));
	QObject::connect(form.actionExit, SIGNAL(triggered()), this, SLOT(ExitHandle()));
	QObject::connect(form.actionOpen, SIGNAL(triggered()), this, SLOT(OpenReportHandle()));
	QObject::connect(form.actionHowto, SIGNAL(triggered()), this, SLOT(HelpHandle()));
	QObject::connect(form.actionAbout, SIGNAL(triggered()), this, SLOT(AboutHandle()));
}

void MainWindow::LoadScenarioHandle()
{
	qDebug() << "load";
	QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Loadtester Files (*.lts)"));
	mainWidget->configdata->loadConfig(fileName.toStdString());
}

void MainWindow::SaveScenarioHandle()
{
	qDebug() << "save";
	QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Loadtester Files (*.lts)"));
	mainWidget->configdata->dumpConfig(fileName.toStdString());
}

void MainWindow::ExitHandle()
{
	this->close();
}

void MainWindow::OpenReportHandle()
{
	qDebug() << "open";
}

void MainWindow::HelpHandle()
{
	qDebug() << "help";
}

void MainWindow::AboutHandle()
{
	qDebug() << "about";
}

